const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('t_operation_logs', {
    id: {
      autoIncrement: true,
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      comment: 'auto id'
    },
    tenant_id: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: 0,
      primaryKey: true,
      comment: '租户id'
    },
    create_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '创建时间'
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '操作用户ID'
    },
    user_name: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '操作用户名'
    },
    oper_type: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '操作类型'
    },
    oper_model: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: '操作模块'
    },
    oper_content: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '操作内容'
    },
    ip: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: 'ip地址'
    },
    geography: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '地理位置'
    },
    browser: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '浏览器'
    },
    os: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '操作系统'
    }
  }, {
    sequelize,
    tableName: 't_operation_logs',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' },
          { name: 'tenant_id' }
        ]
      },
      {
        name: 'idx_user',
        using: 'BTREE',
        fields: [
          { name: 'user_id' }
        ]
      },
      {
        name: 'idx_tenant_id',
        using: 'BTREE',
        fields: [
          { name: 'tenant_id' }
        ]
      }
    ]
  });
};
